package com.bojx.report.core;

import com.alibaba.druid.filter.stat.StatFilter;
import com.alibaba.druid.wall.WallFilter;
import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.kit.PathKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.activerecord.dialect.MysqlDialect;
import com.jfinal.plugin.druid.DruidPlugin;
import com.jfinal.render.ViewType;
import com.jfinal.template.Engine;



public class AppConfig extends JFinalConfig {

	@Override
	public void configConstant(Constants me) {
		loadPropertyFile("appconfig.properties","UTF-8");
		me.setDevMode(getPropertyToBoolean("deMode", false));
		me.setViewType(ViewType.JFINAL_TEMPLATE);
		me.setMaxPostSize(50 * 1024 * 1024);// 上传的文件的最大50M
		me.setEncoding("UTF-8");
	}

	@Override
	public void configEngine(Engine me) {
		me.setDevMode(getPropertyToBoolean("deMode"));
		me.addSharedFunction("WEB-INF/templates/layout.html");
	}

	@Override
	public void configHandler(Handlers me) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void configInterceptor(Interceptors me) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void configPlugin(Plugins me) {
		DruidPlugin druidPlugin = new DruidPlugin(getProperty("jdbcUrl"),getProperty("jdbcUser"), getProperty("jdbcPassword"));
		druidPlugin.addFilter(new StatFilter());// sql 监控
		WallFilter wall = new WallFilter();// 防止sql 注入
		wall.setDbType("mysql");
		druidPlugin.addFilter(wall);
		me.add(druidPlugin);
		
		ActiveRecordPlugin arp = new ActiveRecordPlugin(druidPlugin);
		arp.setDialect(new MysqlDialect());
		arp.setShowSql(getPropertyToBoolean("deMode"));// 开发者模式下开启SQL
		arp.setBaseSqlTemplatePath(PathKit.getRootClassPath()+"/sql");
		arp.addSqlTemplate("test.sql");
		arp.addSqlTemplate("excel.sql");
		arp.addSqlTemplate("statistic.sql");
		me.add(arp);
	}

	@Override
	public void configRoute(Routes me) {
		me.add(new AppRoutes());
	}

	@Override
	public void afterJFinalStart() {
		System.out.println("JFinal start up");
	}

	@Override
	public void beforeJFinalStop() {
		
	}
	
	

}
